package com.www.applyword.adapter;

import android.content.Context;
import android.widget.Button;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.www.applyword.Constants.Constants;
import com.www.applyword.R;
import com.www.applyword.bean.LoginBean;
import com.www.applyword.bean.OrderItemBean;
import com.www.applyword.http.CallBack;
import com.www.applyword.http.HttpClient;
import com.www.applyword.ui.home.EmployedActivity;
import com.www.applyword.utils.ImageUtil;
import com.www.applyword.utils.Utils;

import java.util.HashMap;
import java.util.Map;

/**
 * author : huang
 * date   : 2019/10/21 0021 15:06
 * version: 1.0
 * @author Administrator
 */
public class HomeAdapter2 extends CommonRecyclerAdapter<OrderItemBean> {
    private EmployedActivity context;

    public HomeAdapter2(Context context) {
        super(context, R.layout.item_list_employed);
        this.context = (EmployedActivity) context;
    }


    @Override
    public void onUpdate(BaseAdapterHelper helper, OrderItemBean item, int position) {
        helper.setText(R.id.tv_name,item.getOrderItem_UserName());
        helper.setText(R.id.tv_time,"申请时间:" + item.getOrderItem_CreateTime());
        ImageUtil.setImage(helper.getView(R.id.iv1),(String) item.getOrderItem_UserHeadImg());
         //录用
        if (item.getOrderItem_Type() == 0){
            if (item.getOrderItem_State() == 0){
                helper.setText(R.id.sb1,"录取");
                helper.getView(R.id.sb1).setEnabled(true);
            }else {
                helper.setText(R.id.sb1,"已录取");
                helper.getView(R.id.sb1).setEnabled(false);
            }
        }else {  //承包
            if (item.getOrderItem_State() == 0){
                helper.setText(R.id.sb1,"同意");
                helper.getView(R.id.sb1).setEnabled(true);
            }else {
                helper.setText(R.id.sb1,"已同意");
                helper.getView(R.id.sb1).setEnabled(false);
            }
        }

        helper.getView(R.id.sb1).setOnClickListener(v -> {
            Map<String, Object> params = new HashMap<>();
            params.put("OrderID",item.getOrderItem_OrderID());
            params.put("OrderItemsID",item.getOrderItem_ID());
            HttpClient.get(context, Constants.EMPLOYMENTORDER, params,new CallBack<LoginBean>() {
                @Override
                public void onSuccess(LoginBean result) {
                      Button sb1 = (Button)helper.getView(R.id.sb1);
                    if (item.getOrderItem_Type() == 0){
                        Utils.showToastSafe("录取成功");
                        sb1.setText("已录取");
                        sb1.setEnabled(false);
                    }else {
                        Utils.showToastSafe("同意申请包揽");
                        sb1.setText("已同意");
                        sb1.setEnabled(false);
                    }
                   //  notifyDataSetChanged();
                }
            });
        });
    }
}

